-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Destruct CowData
more graciously by avoiding accidentally exposing a half-destructed buffer.
#100694
Destruct CowData
more graciously by avoiding accidentally exposing a half-destructed buffer.
#100694
Conversation
1c42c9e
to
8e8c214
Compare
Very impressive work! That took quite some sleuthing. I wonder, however, of instead we should delete I think with a CoW datatype taking a pointer to it should be an error, because you should never be storing a reference to the container, you should always take a copy and rely on CoW to make it safe. If a piece of code can't do that, then it shouldn't be using CoW to begin with. Especially now with the move operators, I feel that if you need to do processing on a CoW type to later pass it on, it is only marginally more expensive to just create a LocalVector to then later move it to a Vector for passing on by using |
I have changed my mind a little bit, I think that what I wrote above is true, it is also kind of off topic. When refcount == 0, the only valid state for ptr() is nullptr. Anything else would be a violation of the contract. EDIT: that is to say you are right. :) |
8e8c214
to
e644048
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix for a weird corner case, will likely fix some random crashes.
…a half-destructed buffer. This can avoid problems if any of the destructed objects tries to access the data while it's being destructed.
e644048
to
25cd923
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-approving because of changes.
Thanks! |
This can avoid problems with cyclic references (and breakers).
You may think it's rare, but one such cyclic reference is currently occurring in
GDScript
compiler behavior and leading to half-destructed buffers being copied around. This is not leading to problems right now, because of a coincidental inefficiency inCowData
is leading to a technically unnecessary fork of the data before double destruction can occur. In the worst case, the array would have beenreallocated
halfway through destruction, causing undefined behavior and possibly segmentation faults.My PR removing the unnecessary forks (#100619) triggered the bug more harshly, and this led to very strange leaks occurring.
Importantly,
master
currently fails this simple sanity check:75b7a03
This PR no longer fails the sanity check.
I also added a test to make sure there is no regression of this behavior.